﻿using SqlSugar;

namespace Luka;

/// <summary>
/// 工作单元
/// </summary>
internal class UnitOfWork : IUnitOfWork
{
    /// <summary>
    /// ISqlSugarClient对象
    /// </summary>
    private readonly ISqlSugarClient _client;

    /// <summary>
    /// 构造函数
    /// </summary>
    public UnitOfWork(ISqlSugarClient client) => _client = client;

    /// <summary>
    /// 打开事务
    /// </summary>
    /// <returns></returns>
    public void BeginTran() => _client.AsTenant().BeginTran();

    /// <summary>
    /// 提交事务
    /// </summary>
    /// <returns></returns>
    public void CommitTran() => _client.AsTenant().CommitTran();

    /// <summary>
    /// 回滚事务
    /// </summary>
    /// <returns></returns>
    public void RollbackTran() => _client.AsTenant().RollbackTran();

    /// <summary>
    /// 关闭
    /// </summary>
    public void Close() => _client.AsTenant().Close();
}